package com.crime.crimemonitorclient;

import android.content.Context;
import android.os.AsyncTask;

public abstract class RetainedAsyncTask<Result> extends AsyncTask<Void, Void, Result>
{
	protected AsyncTaskHandler<Result> mAsyncTaskHandler;
	
	public RetainedAsyncTask(AsyncTaskHandler<Result> asyncTaskHandler)
	{
		if(asyncTaskHandler == null)
			throw new NullPointerException("asyncTaskHandler");
		
		this.mAsyncTaskHandler = asyncTaskHandler;
	}

	@Override
	protected void onPreExecute()
	{
		mAsyncTaskHandler.onPreExecute();
	}
	
	@Override
	protected void onPostExecute(Result result)
	{
		mAsyncTaskHandler.onPostExecute(result);
	}
	
	@Override
	protected void onCancelled(Result result)
	{
		mAsyncTaskHandler.onCancelled(result);
	}
	
	public void onAttach(AsyncTaskHandler<Result> asyncTaskHandler)
	{
		mAsyncTaskHandler = asyncTaskHandler;
	}
	
	public void onDetach()
	{
		mAsyncTaskHandler = null;
	}
}
